package cn.px.service.sb.impl;

import com.github.pagehelper.PageHelper;
import cn.px.common.bean.AbstractPageResultBean;
import cn.px.common.util.IdGeneratorUtils;
import cn.px.dao.bean.MyPage;
import cn.px.dao.dto.sb.SbGuigeDTO;
import cn.px.dao.entity.sb.SbGuige;
import cn.px.dao.mapper.sb.SbGuigeMapper;
import cn.px.service.base.impl.BaseServiceImpl;
import cn.px.service.sb.SbGuigeService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.weekend.Weekend;
import tk.mybatis.mapper.weekend.WeekendCriteria;

import java.util.List;

/**
 * @Description 设备规格 service 实现类
 * @author 品讯科技
 * @date 2024-08
 * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
 */
@AllArgsConstructor
@Service("sbGuigeService")
public class SbGuigeServiceImpl extends BaseServiceImpl<SbGuigeMapper, SbGuige, SbGuigeDTO> implements SbGuigeService {
    @Override
    public int batchDelete(List<String> ids) {
        Weekend<SbGuige> weekend = new Weekend<>(SbGuige.class);
        WeekendCriteria<SbGuige, Object> weekendCriteria = weekend.weekendCriteria();
        weekendCriteria.andIn(SbGuige::getId, ids);
        mapper.deleteByExample(weekend);
        return 1;
    }

    @Override
    public AbstractPageResultBean<SbGuige> selectPageInfo(SbGuigeDTO record, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        AbstractPageResultBean<SbGuige> pageInfo = new MyPage(mapper.selectPageList(record));
        return pageInfo;
    }

    @Override
    public SbGuige getModelById(Object id) {
        SbGuige model = mapper.selectById(id);
        return model;
    }

    @Override
    public List<SbGuige> getModelListByDTO(SbGuigeDTO model) {
        List<SbGuige> result = super.getModelListByDTO(model);
        return result;
    }

    @Override
    public SbGuige saveModelByDTO(SbGuigeDTO model) {
        Weekend<SbGuige> weekend = new Weekend<>(SbGuige.class);
        weekend.weekendCriteria().andIsNotNull(SbGuige::getId);
        Integer count = mapper.selectCountByExample(weekend);
        model.setNo(IdGeneratorUtils.getGuigeNo(++count));
        return super.saveModelByDTO(model);
    }

}
